import { mapState, mapMutations } from 'vuex';

export default {
  data () {
    return {
      // pagination: {
      //   total: 0,
      //   current: 1,
      //   size: 10,
      //   pages: 0
      // },
      // inited: false
    }
  },
  computed: {
    ...mapState('supplier/baseList', [
      'formItemData',
    ])
  },
  created () {
    if (this.formItemData && Object.keys(this.formItemData).length) {
      for (let [k, v] of Object.entries(this.formItemData)) {
        if (Object.keys(this.pagination).includes(k)) {
          this.pagination[k] = v
        } else {
          this.formData[k] = v
        }
      }
    }
    // console.log('created set pagination:>> ', this.pagination);
    // console.log('created set formData:>> ', this.formData);
  },
  methods: {
    ...mapMutations('supplier/baseList', [
      'setFormItemData',
    ]),
    // // 表单查询
    // handleQueryForm (data) {
    //   this.formData = data
    //   this.getTableData(1)
    // },
    // // 页码切换
    // handlePageChange (current) {
    //   this.getTableData(current)
    // },
    // // 每页条数切换
    // handlePageSizeChange (size) {
    //   this.getTableData(1, size)
    // },
  },
  beforeRouteLeave (to, from, next) {
    // 查看子页面时保存查询表单字段
    // 需要保存父页面搜索条件的子页面router name列表
    const pathList = [
      'auditLog',
      'viewFreight',
      'viewSupplier',
      'batchHandover',
      'convertToQualified',
      'addRegularPriceSupervision',
      'addTempPriceSupervision',
      'editRegularPriceSupervision',
      'editTempPriceSupervision',
      'viewRegularPriceSupervision',
      'viewTempPriceSupervision',
    ]
    if (!pathList.includes(to.name)) {
      // console.log('beforeRouteLeave to name :>> ', to.name);
      this.setFormItemData(null);
    }
    next()
  }
}
